﻿using System;
using System.Collections.Generic;
using WebUI.BL.ProductBL;
using WebUI.BL.Products;
using WebUI.BL.ProductSizeBL;
using WebUI.BL;

namespace WebUI
{
    public partial class ProductDetails : System.Web.UI.Page
    {
        public string productcode = "";
        public int productno = 0;
        public string productname = "";
        public string productimagemedium = "";
        public string productimagelarge = "";
        public string productprice = "";
        public string productdisplayprice = "";
        public string productdesc = "";

        public int colorno = 0;     

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                productcode = (string)Request.QueryString["productcode"];
                if(productcode != null && productcode != "")
                    BindData(productcode);
            }
        }

        private void BindData(string productcode)
        {
            WebFunction function = new WebFunction();
            ProductBL repository = new ProductBL();
            ProductSizeBL repositorysize = new ProductSizeBL();
            ProductColorBL repositorycolor = new ProductColorBL();
            ProductImagesBL repositoryimage = new ProductImagesBL();

            List<MODEL_SP_FONT_PRODUCT> productdetails = repository.Get_Font_ProductDetails(Convert.ToInt32(productcode));
            if (productdetails != null)
            {
                foreach (var x in productdetails)
                {
                    productno = x.ProductNo;
                    productname = x.ProductName;
                    productimagemedium = x.ImgMedium;
                    productimagelarge = x.ImgLarge;
                    productdesc = x.Description;
                    productdisplayprice = function.FormatNumber(Convert.ToInt32(x.DisplayPrice));
                }

                List<MODEL_SP_FONT_PRODUCT_COLOR> productcolor = repositorycolor.Get_Font_ProductColor(productno);
                rptProcolor.DataSource = productcolor;
                rptProcolor.DataBind();

                if (productcolor != null)
                {
                    foreach (var y in productcolor)
                    {
                        colorno = Convert.ToInt32(y.ColorNo);
                        break;
                    }

                    rptProsize.DataSource = repositorysize.Get_Font_ProductSize(productno, colorno);
                    rptProsize.DataBind();                    
                }
            }

            rptImage.DataSource = repositoryimage.Get_Font_ProductImage(productno);
            rptImage.DataBind();
        }
    }
}